/**
 * Created by wangjiakun on 2018/6/14 0014.
 */
import config from 'config'
import httpFetch from 'share/httpFetch'
import configureStore from 'stores';

export default {
  //获取差补规则基础数据
  getSubsidyBaseData(){
    return httpFetch.get(`${config.baseUrl}/api/travel/subsidies/rule/base/setting`);
  },

  //保存差补规则基础数据
  saveSubsidyBaseData(param,setOfBooksId){
    return httpFetch.post(`${config.baseUrl}/api/travel/subsidies/rule/base/setting?setOfBooksId=${setOfBooksId}`,param);
  },

  //获取差补规则单据列表
  getSubsidyListData(booksID){
    return httpFetch.get(`${config.baseUrl}/api/travel/subsidies/rule/forms`, { booksID });
  },

  //获取差补规则&详情
  getSubsidyBaseAndList(params){
    return httpFetch.get(`${config.baseUrl}/api/travel/subsidies/rule/base/setting/v2`, params );
  },

  //获取差补规则单据下差补类型列表
  getSubsidyTypeData(formOID){
    return httpFetch.get(`${config.baseUrl}/api/travel/subsidies/rule/list?formOID=${formOID}`);
  },

  //获取单据默认基础规则数据
  getSubsidyTypeBaseData(formOID){
    return httpFetch.get(`${config.baseUrl}/api/travel/subsidies/rule/dimension?formOID=${formOID}`);
  },

  //保存规则生成器头部数据
  saveSubsidyHead(param){
    return httpFetch.post(`${config.baseUrl}/api/travel/subsidies/rule/dimension`,param);
  },

  //获取差补城市
  getSubsidyCityData(){
    return httpFetch.get(`${config.baseUrl}/api/levels/my?deleted=false&page=0&size=1000`);
  },

  /**
   *
   * @param codeType 币种 CYN 等
   * @param lan 语言 zh_cn
   * @param bid
   * @param tenantId
     * @returns {*}
     */
  getCurrentCodeData(codeType, lan, bid, tenantId){
    return httpFetch.get(`${config.baseUrl}/api/currency/rate/list?baseCurrencyCode=${codeType}&language=${lan}&page=0&setOfBooksId=${bid}&size=1000&tenantId=${tenantId}`);
  },

  //获取表单数据
  getSubsidyFormData(formOID){
    return httpFetch.get(`${config.baseUrl}/api/travel/subsidies/rule/form?formOID=${formOID}`);
  },

  //获取batchCode,添加新规则使用
  getBatchCode(){
    return httpFetch.get(`${config.baseUrl}/api/travel/subsidies/condition/batch/code`);
  },

  //查看规则名称是否重复
  checkedRuleNameIsRepeat(expenseTypeOID, formOID, name, travelSubsidiesRuleID){
    let params ={
      expenseTypeOID,
      formOID,
      name,
      travelSubsidiesRuleID: travelSubsidiesRuleID || ''
    };
    //?expenseTypeOID=${expenseTypeOID}&formOID=${formOID}&name=${name}${travelSubsidiesRuleID ? '&travelSubsidiesRuleID=' + travelSubsidiesRuleID : ''}
    return httpFetch.get(`${config.baseUrl}/api/travel/subsidies/rule/check/name`,params);
  },

  //保存规则
  saveRule(params,setOfBooksId){
    return httpFetch.post(`${config.baseUrl}/api/travel/subsidies/rule?setOfBooksId=${setOfBooksId}`,params);
  },

  //获取自定义的数据值
  getFieldValues(id){
    return httpFetch.get(`${config.baseUrl}/api/custom/enumerations/${id}`);
  },

  //删除规则
  deleteRule(id){
    return httpFetch.delete(`${config.baseUrl}/api/travel/subsidies/rule?id=${id}`);
  },

  //获取单个规则的详情
  getRuleDetail(id){
    return httpFetch.get(`${config.baseUrl}/api/travel/subsidies/rule?id=${id}`);
  },

  //更新规则
  updateRule(params,setOfBooksId){
    return httpFetch.put(`${config.baseUrl}/api/travel/subsidies/rule?setOfBooksId=${setOfBooksId}`,params);
  }
}
